<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
    String key = input.getDesc("key", "");
    if ("".equals(key)) {
        msg = new Message(30041, "关键字不能为空");
        Tools.encryptPrint(out, msg);
        return;
    }
    List users = QBuilder.db("basedb").queryHql("select new map(id as id, userName as user_name, nickName as nick_name, avatar as avatar, type as type) from User where hospital = " + hospital + " and status=" + STATUS_ENABLE+" and id !="+token.getUid()+" and (userName like '%"+ key +"%' or phone like '%"+ key +"%')");
    if (isEmpty(users)) {
        msg = new Message(30041, "没有搜索到任何数据");
        Tools.encryptPrint(out, msg);
        return;
    }
    String uids = "-1";
    for (int i = 0; i < users.size(); i++) {
        Map map = (Map)users.get(i);
        uids += "," + Tools.getDesc(map.get("id"), "-1");
    }
    List<UserProfile> userProfiles = QBuilder.db("basedb").select().from("UserProfile").where(new Where("status= ", STATUS_ENABLE).and("hospital=", hospital).and("SELF=", SELF).and("uid in ("+ uids +")")).query().getResultObj();
    for (int i = 0; i < users.size(); i++) {
        Map map = (Map)users.get(i);
        String id = Tools.getDesc(map.get("id"), "-1");
        for (int j = 0; j < userProfiles.size(); j++) {
            UserProfile userProfile = userProfiles.get(j);
            String uid = userProfile.getUid() + "";
            if (id.equals(uid)) {
                Long birth = Tools.getLong(userProfile.getBirthday() + "", -1L);
                map.put("birthday", birth < 0 ? "" : DateUtil.formatDate(new Date(birth)));
                map.put("gender", Tools.getDesc(userProfile.getGender() + "", ""));
                map.put("self", Tools.getDesc(userProfile.getSelf() + "", "0"));
                map.put("age", Tools.getDesc(userProfile.getAge() + "", ""));
                map.put("phone", Tools.getDesc(userProfile.getPhone() + "", ""));
                map.put("card_type", Tools.getDesc(userProfile.getCardType() + "", ""));
                map.put("medical_type", Tools.getDesc(userProfile.getMedicalType() + "", ""));
                map.put("name", Tools.getDesc(userProfile.getName() + "", ""));
                map.put("json", userProfile.getJson());
                userProfiles.remove(userProfile);
                break;
            }
        }
    }
    msg.put("data", users);
    Tools.encryptPrint(out, msg);
%>
